<?PHP
/**
* @name:报表格式化类，配合前台Ereports.js类生成格式化数
* @version : 0.1.0
* @copyright Copyright (C) 2007 - 2008 Open Source Matters. All rights reserved.
* @modify by :o2script
* @modify date:2007.11.12
*/
class Ereports extends Ereports_obj implements HeadInterface{
	/*报表名称*/
	var $_name = '';
	/*报表打印者*/
	var $_user = '';
	/*报表打印时间*/
	var $_date = '';	
	/*报表尾部结束语*/
	var $_end = '';
	/*数据标题格子对象数组*/
	var $_cols = array();
	/* 参与统计的栏目数 */
	var $_total_cols_num = 0;
	/*数据对象数组*/
	var $_rows = array();
	/*原始数据对象数组*/
	var $_rows_clone = array();
	/* 是否要总计 */
	var $_total_all = true;
	/* 报表宽度 */
	var $_table_width = '100%';
	/* 表头的说明 */
	var $_top_str = array();
	/* 表结尾的说明 */
	var $_bottom_str = array();
	/*报表头对象*/
	var $_reports_head;
	/*存储报表头数组的变量*/
	var $_arr_title = '';
	/*存储报表图数组的变量*/
	var $_arr_cpic = '';
	
	/* 初始化自己 */
	static function &singleton(){
		static $instance;
		if(!isset($instance)){
			$instance=new Ereports();
		}
		return $instance;
	}
	
	/*构造函数*/
	function __construct(){
		parent :: __construct();
		$args = func_get_args();
		if(count($args) == 1) $this->init($args[0]);
		$this->_reports_head = new Ereports_head();
	}
	
	#******************************************自定义报表头和统计图********************************
	#创建报表头的方法
	function createHead($_obj){
		return $this->_reports_head->createHead($_obj);
	}
	
	#自定义报表头
	function title(){
		$args = func_get_args();
		if(count($args)>0){
			$this->_arr_title = $args[0];
		}else{
			$_arr_title = array();
		}
	}
	
	#返回格式化后的报表统计图数据
	function createCountPic($_args,$_objArr,$totals){
		return $this->_reports_head->createCountPic($_args,$_objArr,$totals);
	}
	
	#获取统计图数据
	function countPic(){
		$args = func_get_args();
		if(count($args)>0){
			$this->_arr_cpic = $args[0];
		}else{
			$this->_arr_cpic = array();
		}
	}
	
	#输出报表图表数据
	function exportPic(){
		#组装报表图表数据
		return $this->createCountPic($this->_arr_cpic,$this->_cols,$this->_rows);	
	}
	
	#返回格式化后的报表统计图数据(第二个模式)
	function createCountPicSp($_args,$_objArr,$totals){
		return $this->_reports_head->createCountPicSp($_args,$_objArr,$totals);
	}
	#输出报表图表数据(第二个模式)
	function exportPicSp(){
		#组装报表图表数据
		return $this->createCountPicSp($this->_arr_cpic,$this->_cols,$this->_rows);	
	}
	#******************************************************************************************
	
	
	/* 列数目 */
	function colsNum(){
		return count($this->_cols);
	}
	/* 行数目 */
	function rowsNum(){
		return count($this->_rows_clone);
	}
	/*初始化*/
	function init(){
		/*一些默认值*/
		$args = func_get_args();
		if(count($args) == 1){
			foreach($args[0] as $key => $value){
				$this->set($key,$value);		
			}
		}	
	}
	/*设置和取标题栏*/
	function cols(){
		$this->_total_cols_num = 0;
		$args = func_get_args();
		$group_i = 1;
		if(count($args) > 0){
			foreach($args as $value){
				/*放置clos*/
				$_temp = new Ereports_cols();
				foreach($value as $k => $val){
					$_temp->set($k,$val);
				}
				
				if($_temp->_total != "none"){
					$this->_total_cols_num++;
				}
				# 是否分组，增加分组序列
				if($_temp->_group == "1"){
					$_temp->_group_index = $group_i++;
				}
				# 增加这个栏
				$this->_cols[] = $_temp;
				/*要释放吗？对。*/
				$_temp = NULL;
			}
			/*设置完了平均一下他们的width*/
			$this->avgCols();
			/* 检查，分组和统计不能同时存在 */
			$this->checkTotal();
		}else{
			//格式化成数组输出
			$returns = array();
			$temp = $this->get('_cols');
			foreach($this->get('_cols') as $val){
				$returns[] = (get_object_vars($val));
			}
			$temp = NULL;
			return $returns;
		}
	}

	/* 检查，分组和统计不能同时存在 */
	function checkTotal(){
		foreach($this->_cols as $k=>$v ){
			if($v->_group){
				$this->_cols[$k]->_total = 'none';
			}
		}
	}
	/*平均分割cols的长度*/
	function avgCols(){
		$args = func_get_args();
		if(count($args) == 0){
			//平均吧
			$_tmp_cols_num = $this->colsNum();
			if($_tmp_cols_num != 0){
				/*得到平均值,不带小数点，取小于等于他的最大整数*/
				$avrage_num = floor(100/$_tmp_cols_num);
				for($ii=0; $ii<$_tmp_cols_num; $ii++){
					$this->_cols[$ii]->set('_width',$avrage_num);
				}			
			}else{
				return false;
			}
		}else{
			/*进行自定义设置*/
			$_give_nums = 0;
			$_give_width = 0;
			foreach($args as $value){
				if($_give_nums == $this->colsNum()) break;
				$this->_cols[$_give_nums]->set('_width',$value);
				$_give_nums++;
				$_give_width += $value;
				if($_give_width > 100) $this->error('cols总长度超过100!');
			}
			$_give_width = 100 - $_give_width;
			if(($this->colsNum() - $_give_nums) > 0 ){
				$_give_width = floor($_give_width/($this->colsNum() - $_give_nums));
				for($ii=$_give_nums; $ii<$this->colsNum(); $ii++){
					$this->_cols[$ii]->set('_width',$_give_width);
				}
			}
		}	
	}
	/*设置和取数据栏*/
	function rows(){
		$args = func_get_args();
		if(count($args) > 0){
			foreach($args[0] as $val){
				$this->_rows[] = $val;
				$this->_rows_clone[] = $val;
			}
		}else{
			return $this->get('_rows');	
		}
	}
	/* 合计某一行的某一栏 */
	function totalCols($row_i,$col_i){
		# 如果当前没有任何统计栏，则返回空
		if($this->_total_cols_num == 0){
			return false;
		}
		
	  #得到向上计算多少行
		$up_num = 0;
		$goon = true;
		$ii = $row_i;
		$now_str = '';
		for($jj=$col_i ; $jj>=0 ;  $jj--){
			$now_str .= $this->_rows[$ii][$jj];
		}
		do{
			$tmp_str = '';
			for($jj=$col_i ; $jj>=0 ;  $jj--){
				$tmp_str .= $this->_rows[$ii][$jj];
			}
			if($now_str == $tmp_str){
				$up_num++;
			}else{
				$goon = false;
			}
			# 行向上移动
			$ii--;
			if($ii < 0){
				$goon = false;
			}
		}while($goon);
	 	# 组装html
		$total_html = '<tr class="rpt_row_total rpt_row_total_'.$this->_cols[$col_i]->_group_index.'" >';
		for($i=($col_i - 1) ; $i>=0 ; $i--){
			$total_html .= '<td class="nothing" ></td>';
		}
		$total_html .= '<td align="'.$this->_cols[$col_i]->_align.'" >'.$this->_rows[$row_i][$col_i].' 统计:</td>';

		# 剩下的有累计就要进行累计了
		for($jj=($col_i + 1) ; $jj < count($this->_cols) ;  $jj++){
			switch($this->_cols[$jj]->_total){
				case 'sum':
					$tmp_sum = 0;
					for($kk=0; $kk<$up_num ; $kk++){
						$tmp_sum += $this->_rows[ ($row_i-$kk) ][$jj];
					}
					if($this->_cols[$jj]->_type == "int"){

						$tmp_sum = intval($tmp_sum);
					}else if(strpos($this->_cols[$jj]->_type,'dec') !== false){
						$tmp_sum = sprintf("%.".intval(substr($this->_cols[$jj]->_type,3))."f",$tmp_sum);
					}
					$total_html .= '<td align="'.$this->_cols[$jj]->_align.'" >'.$tmp_sum.'</td>';
					break;
				case 'count':
					$total_html .= '<td align="'.$this->_cols[$jj]->_align.'" >'.intval($up_num).'</td>';
					break;
				case 'avg':
					$tmp_sum = 0;
					for($kk=0; $kk<$up_num ; $kk++){
						$tmp_sum += $this->_rows[ ($row_i-$kk) ][$jj];
					}
					if($up_num == 0){
						$tmp_sum = 0;
					}else{
						$tmp_sum = $tmp_sum/intval($up_num);
					}
					$tmp_sum = sprintf("%.".intval(substr($this->_cols[$jj]->_type,3))."f",$tmp_sum);
					$total_html .= '<td align="'.$this->_cols[$jj]->_align.'" >'.$tmp_sum.'</td>';
					break;					
				case 'max':
					$tmp = 0;
					if(count($up_num) == 0){
						$tmp = '';
					}else{
						$tmp = 	$this->_rows[$row_i][$jj];
						for($kk=0; $kk<$up_num ; $kk++){
							if($tmp < $this->_rows[ ($row_i-$kk) ][$jj]){
								$tmp = $this->_rows[ ($row_i-$kk) ][$jj];
							}
						}
					}
					if($this->_cols[$jj]->_type == "int"){
						$tmp = intval($tmp);
					}else if(strpos($this->_cols[$jj]->_type,'dec') !== false){
						$tmp = sprintf("%.".intval(substr($this->_cols[$jj]->_type,3))."f",$tmp);
					}
					$total_html .= '<td align="'.$this->_cols[$jj]->_align.'" >'.$tmp.'</td>';
					break;
				case 'min':
					$tmp = 0;
					if(count($up_num) == 0){
						$tmp = '';
					}else{
						$tmp = 	$this->_rows[$row_i][$jj];
						for($kk=0; $kk<$up_num ; $kk++){
							if($tmp > $this->_rows[ ($row_i-$kk) ][$jj]){
								$tmp = $this->_rows[ ($row_i-$kk) ][$jj];
							}
						}
					}
					if($this->_cols[$jj]->_type == "int"){
						$tmp = intval($tmp);
					}else if(strpos($this->_cols[$jj]->_type,'dec') !== false){
						$tmp = sprintf("%.".intval(substr($this->_cols[$jj]->_type,3))."f",$tmp);
					}
					$total_html .= '<td align="'.$this->_cols[$jj]->_align.'" >'.$tmp.'</td>';
					break;
				default:
					$total_html .= '<td class="total_nothing" ></td>';
					break;	
			}
		}
		
		$total_html .= '</tr>';
		return $total_html;
	}

	/*格式化输出这个table*/
	function export(){
		/*格式化数据先*/
		$this->format();
		/* 头 */
		$html = '';
		if($this->_name != ""){
			$html .= '<div class="rpt_caption">'.$this->_name.'</div>';
		}
		if(is_array($this->_top_str)){
			foreach($this->_top_str as $key=>$val){
				$html .= '<div class="rpt_top_str">'.$val.'</div>';
			}
		}
		if($this->_user != ""){
			$html .= '<div class="rpt_author">打印人:'.$this->_user.'</div>';
		}
		if($this->_date != ""){
			$html .= '<div class="rpt_date">打印时间:'.$this->_date.'</div>';
		}

		$html .= '<div class="rpt_scorll"><table border="1" width="'.$this->_table_width.'"><thead>';
		
		#****************************自定报表头**********************************
		#如果表头有变动就自定义显示，否则按照原来的显示
		if(!empty($this->_arr_title)){
			$html .= $this->createHead($this->_arr_title);
		}else{
			$html .= '<tr class="rpt_title">';
				foreach($this->_cols as $key=>$col){
					$html .= '<td style="'.$col->_css.'" width="'.$col->_width.'%" align="center" >'.$col->_text.'</td>';
				}
			$html .= '</tr>';
		}
		#****************************自定报表头**********************************
		
		$html .= '</thead>';
		$html .= '<tbody>';
		for($row_i = 0 ; $row_i < $this->rowsNum() ; $row_i++){
			$tmp = '';
			$row = $this->_rows[$row_i];
			
			if($row_i == 0){
				# 第一行
				$tmp .=  '<tr class="rpt_row">';
				foreach($row as $key=>$v){
					$tmp .= '<td align="'.$this->_cols[$key]->_align.'" >'.$v.'</td>';
				}
				$tmp .=  '</tr>';
			}else{
				# 非第一行
				if($row_i%2!=0){
					$class = "rpt_row_sec";
				}else{
					$class = "rpt_row";
				}

				$tmp .= '<tr class='.$class.'>';
				foreach($this->_cols as $ii=>$cols){
					if($cols->_group){
						//当前栏的对比字符串
						$compare_cur = '';
						$compare_pre = '';
						for($jj=$ii ; $jj>=0 ;  $jj--){
							$compare_cur .= $this->_rows[$row_i][$jj];
							$compare_pre .= $this->_rows[($row_i - 1)][$jj];
						}
						if($compare_cur != $compare_pre){
							#如果不相等，进行前一组类别的分组统计，用通用函数搞定
							$tmp = $this->totalCols(($row_i - 1),$ii).$tmp;
							$tmp .= '<td align="'.$cols->_align.'" >'.$row[$ii].'</td>';
						}else{
							$tmp .= '<td align="'.$cols->_align.'" class="nothing" >.</td>';
						}
					}else{
						$tmp .= '<td align="'.$cols->_align.'" >'.$row[$ii].'</td>';
					}	
				}
				$tmp .= '</tr>';
			}
			# 最后再来添加行
			$html .= $tmp;
		}
		# 剩余的总计
		if(count($this->_rows) != 0){
			$tmp = '';
			foreach($this->_cols as $ii=>$cols){
				if($cols->_group){

					$tmp = $this->totalCols((count($this->_rows) - 1),$ii).$tmp;
				}	
			}
			$html .= $tmp; 
		}
		
		# 合计
		if(count($this->_rows) != 0 && $this->_total_cols_num != 0 && $this->_total_all ){
			$totals = array();
			foreach($this->_cols as $ii=>$cols){
					$totals[$ii] = '';
					switch($cols->_total){
						case 'sum':
							$tmp = 0;
							foreach($this->_rows as $jj=>$rows){
								$tmp += $rows[$ii];
							}
							$totals[$ii] = $tmp;
							if($cols->_type == "int"){
								$totals[$ii] = intval($totals[$ii]);
							}else if(strpos($cols->_type,'dec') !== false){
								$totals[$ii] = sprintf("%.".intval(substr($cols->_type,3))."f",$totals[$ii]);
							}
							break;
						case 'count':
							$totals[$ii] = intval(count($this->_rows));
							break;
						case 'avg':
							$tmp = 0;
							foreach($this->_rows as $jj=>$rows){
								$tmp += $rows[$ii];
							}
							if(count($this->_rows) == 0){
								$tmp = 0;
							}else{
								$tmp = $tmp/count($this->_rows);
							}
							$totals[$ii] = sprintf("%.".intval(substr($cols->_type,3))."f",$tmp);
							break;
						case 'max':
							$tmp = 0;
							if(count($this->_rows) == 0){
								$tmp = '';
							}else{
								$tmp = 	$this->_rows[0][$ii];
								foreach($this->_rows as $jj=>$rows){
									if($tmp < $rows[$ii]){
										$tmp = $rows[$ii];
									}
								}
							}
							$totals[$ii] = $tmp;
							if($cols->_type == "int"){
								$totals[$ii] = intval($totals[$ii]);
							}else if(strpos($cols->_type,'dec') !== false){
								$totals[$ii] = sprintf("%.".intval(substr($cols->_type,3))."f",$totals[$ii]);
							}						
							break;
						case 'min':
							$tmp = 0;
							if(count($this->_rows) == 0){
								$tmp = '';
							}else{
								$tmp = 	$this->_rows[0][$ii];
								foreach($this->_rows as $jj=>$rows){
									if($tmp > $rows[$ii]){
										$tmp = $rows[$ii];
									}
								}
							}
							$totals[$ii] = $tmp;
							if($cols->_type == "int"){
								$totals[$ii] = intval($totals[$ii]);
							}else if(strpos($cols->_type,'dec') !== false){
								$totals[$ii] = sprintf("%.".intval(substr($cols->_type,3))."f",$totals[$ii]);
							}						
							break;
						default:
							break;	
					}
			}

			$totals[0] = '合计:' . $totals[0];
			$html .=  '<tr class="rpt_total">';
			foreach($totals as $key=>$v){
				if($v == ""){
					$html .= '<td class="total_nothing"></td>';
				}else{
					$html .= '<td align="'.$this->_cols[$key]->_align.'" >'.$v.'</td>';
				}
			}
			$html .=  '</tr>';
		}
		$html .= '</tbody></table></div>';
		
		if(is_array($this->_bottom_str) && count($this->_bottom_str) > 0){
			foreach($this->_bottom_str as $key=>$val){
				$html .= '<div class="rpt_bottom_str">'.$val.'</div>';
			}
		}
		
		# 结尾
		if($this->_end != ""){
			$html .= '<div class="rpt_bootom_class">'.$this->_end.'</div>';
		}
		return $html;
	}
	/* 组装一行数据 */
	function setupRow($rs,$cla="rpt_row"){
		$tmp = '';
		$tmp .=  '<tr class="'.$cla.'">';
		foreach($rs as $k=>$v){
			$tmp .= '<td align="'.$this->_cols[$k]->_align.'" >'.$v.'</td>';
		}
		$tmp .=  '</tr>';
		return $tmp;
	}
	/*根据cols对象数组格式化数据*/
	function format(){
		/*恢复原始数据，然后再进行格式化*/
		$this->_rows = $this->_rows_clone;
		foreach($this->_cols as $key=>$col){
			if($col->get("_type") == "int"){
				foreach($this->_rows as $k=>$row){
					$this->_rows[$k][$key] = intval($row[$key]);
				}		
			}else if(strpos($col->get("_type"),'dec') !== false){
				foreach($this->_rows as $k=>$row){
					$this->_rows[$k][$key] = sprintf("%.".intval(substr($col->get("_type"),3))."f",$row[$key]);
				}
			}
			if($col->get("_fun") != ''){
				if(function_exists($col->get("_fun"))){
					foreach($this->_rows as $k=>$row){
						$this->_rows[$k][$key] = call_user_func($col->get("_fun"),$row[$key]);
					}
				}else{
					$this->error('['.$col->get("_fun").']处理函数未定义!');
				}
			}
		}
	}
}
/**
*表格标题格子对象
		_text:标题名称(默认为：未定义)
		_type:字段类型
			(str:字符串，默认值)
			(int:整数)
			(dec2:dec表示是float型，后面的数字表示保留几位小数)
		_align:改列对齐方式，并不是指标题，是指这列下面的数据,标题栏始终居中
			(center:居中 默认值)
			(left:居左)
			(right:居右)
		_css:单元格的css样式,默认为空
		_fun:格式化函数,对值进行统一的函数处理。这个函数要在本页面定义，或者本页面运行能检测， 默认没有
		_group：是否分组(可对字段进行分类汇总，支持多级分组,!!分组字段必须放到最前列）
			(false:不属分组,默认值)
			(true:属于分组)
		_total：统计类型(注意：是分组不能支持统计)
			(none:无统计,默认值)
			(sum:求和)
			(count:计数)
			(avg:平均)
			(max:最大值)
			(min:最小值)
*/
class Ereports_cols extends Ereports_obj{
	/*内容*/
	var $_text = '';
	/* 本列数据类型 */
	var $_type = 'str';
	/*对齐属性*/
	var $_align = 'center';
	/*本栏的CSS*/
	var $_css = '';
	/*格式化函数*/
	var $_fun = '';
	/*字段所占长度*/
	var $_width = '0';
	/*是否分组*/
	var $_group = false;
	/* 分组序列 */
	var $_group_index = 0;
	/*当前列汇总方式*/
	var $_total = 'none';
	/*表头组*/
	var $_title_group = '';
	/*构造函数*/
	function __construct(){
		parent :: __construct();
		$args = func_get_args();
		/*只能设置一个text，并且为一个参数*/
		if(count($args) == 1) $this->set('_text',$args[0]);
	}
	/*设置和得到text*/
	function text(){
		$args = func_get_args();
		if(count($args) == 1){
			$this->set('_text',$args[0]);		
		}else{
			return $this->get('_text');	
		}
	}
	/*等待扩充......*/
}
/**
*报表祖先类
*/
class Ereports_obj{
	/*构造函数*/
	function __construct() {
	}
	/*兼容构造函数*/
	function EObject() {
		$args = func_get_args();
		if (method_exists($this, '__destruct')) {
			register_shutdown_function(array (
				& $this,
				'__destruct'
			));
		}
		call_user_func_array(array (& $this,'__construct'), $args);
	}
	/*设置属性函数*/
	function set($property, $value = NULL) {
		return $this-> $property = $value;
	}
	/*得到属性函数*/
	function get($property, $default = NULL) {
		if (isset ($this-> $property)) {
			return $this-> $property;
		} else {
			return $default;
		}
	}
	/*转换为字符串*/
	function toString() {
		return get_class($this);
	}	
	/*错误*/
	function error($_text){
		exit($_text);
	}
}

/*定义报表头和统计图数据接口*/
interface HeadInterface{
	/*报表头创建函数*/
	function createHead($_obj);
	#获取统计图数据
	function createCountPic($_args,$_objArr,$totals);
	#获取统计图数据(样式二)
	function createCountPicSp($_args,$_objArr,$totals);
}

/*定义报表头和统计图数据类实现自定义报表头和统计图数据接口*/
class Ereports_head implements HeadInterface{
	/*一些变量和数组*/
	var $html = '';
	var $i = 0;
	var $j = 0;
	var $_span = '';
	var $_pic_n = array();
	var $_tempArr = array();
	var $_pic_bn = array();
	var $_tempStr = '';
	var $tempID = 0;
	var $_find = false;
	/*构造函数*/
	function __construct(){}
	
	/*报表头创建函数*/
	function createHead($_obj){
		$this->tempID = 0;
		for($this->i=0;$this->i<count($_obj);$this->i++){
			if($this->tempID==0){
				$this->tempID = count($_obj);
			}
			if($this->_find){
				$this->tempID = $this->tempID - 1;
				$this->_find = false;
			}
			$this->html .= "<tr class='rpt_title'>";
			for($this->j=0;$this->j<count($_obj[$this->i]);$this->j++){
				if(Empty($_obj[$this->i][$this->j]['merge'])){
					$this->span  = "rowspan = ".$this->tempID;
				}else{
					$this->span = "colspan=".$_obj[$this->i][$this->j]['merge'];
					$this->_find = true;
				}
				$this->html .= "<td ".$this->span." align='center'>".$_obj[$this->i][$this->j]['text']."</td>";
			}
			$this->html .= "</tr>";
		}
		
		return $this->html;
	}
	
	#获取统计图数据(第二模式)
	function createCountPicSp($_args,$_objArr,$totals){
		$a = array();
		$b = array();
		$c = array();
		$d = array();
		$e = array();
		$f = array();
		$g = array();
		$color = array();
		$width = array();
		$empStr = '';
		$empStr2 = '';
		$_spArr = 0;
		$SMD = '';
		foreach($_args as $k=>$v){
			foreach($v as $kk=>$vv){
				if($empStr==''){
					$empStr = $vv['type'];
					$empStr2 = $vv['name'];
				}else{
					$empStr = $empStr.",".$vv['type'];
					$empStr2 = $empStr2.",".$vv['name'];
				}
			}
		}
		
		$a = split("\\,",$empStr);	
		$a = array_unique($a);
		foreach($a as $p=>$x){
			$b[] = $x; 
		}
		
		$ck = split("\\,",$empStr2);	
		$ck = array_unique($ck);
		foreach($ck as $cp=>$cx){
			$e[] = $cx; 
		}
		foreach($e as $ke=>$ve){
			foreach($b as $k1=>$v1){
				foreach($_args as $k2=>$v2){
					foreach($v2 as $k3=>$v3){
						
						if($v1==$v3['type']&&$ve==$v3['name']){
							$f = $v3['name'];
							$color = $v3['color'];
							$width = $v3['width'];
							if($_spArr==0){
								$_spArr = $v3['value'];
							}else{
								$_spArr = $_spArr+$v3['value'];
							}	
						}
					}
				}
				
				$this->_pic_n[] = $v1;
				$this->_pic_n[] = $_spArr;
				$this->_pic_n[] = $f;
				$this->_pic_n[] = $color;
				$this->_pic_n[] = $width;
				$_spArr = 0;
				$c[] = $this->_pic_n;
				
				$this->_pic_n = array();
			}
		}
	
		foreach($c as $fk=>$fv){

			$e2[$fv[0]] = $fv[1];
			$c2[$fv[0]] = $fv[3];
			$g2[] = $fv[2];
			$abc = array(
				$fv[2],#公司名
				$e2,
				$c2,
				$fv[4],
				$fv[5]
			);
			if(($fk+1)%count($b)==0){
				$edf[] = $abc;
				$abc = array();
				$e2 = array();
				$g2 = array();
				$c2 = array();
			}
		}

		foreach($edf as $lk=>$lv){
			
			$temp1[] = $lv[0];
			$temp2 = $lv[2];
			$temp3 = $lv[3];
			$SMD = $lv[4];
			if($lk>0){
				
				foreach($lv[1] as $kw=>$lw){
					foreach($temp4 as $kkw=>$llw){
						if($kw==$kkw){
							$hbr[$kw] = $hbr[$kw].",".$lw;
						}
					}
				}

			}else{
				$temp4 = $lv[1];#存放需要比较的数组(取的参照对象为$edf数组的第一个元数)
			}
			
			if(empty($hbr)){
				$hbr = $temp4;
			}
		}
		
		$results = array(
			$temp1,
			$hbr,
			$temp2,
			$temp3,
			$SMD
		);
		
		#debug($results);
		
		return $results;
		
	}
	#获取统计图数据
	function createCountPic($_args,$_objArr,$totals){
			$a = array();
			$b = array();
			$c = array();
			$d = array();
			$e = array();
			$f = array();
			$g = array();
			$color = array();
			$width = array();
			$empStr = '';
			$empStr2 = '';
			$_spArr = 0;
			
			foreach($_args as $k=>$v){
				foreach($v as $kk=>$vv){
					if($empStr==''){
						$empStr = $vv['name'];
					}else{
						$empStr = $empStr.",".$vv['name'];
					}
				}
			}
			
			$a = split("\\,",$empStr);	
			$a = array_unique($a);
			foreach($a as $p=>$x){
				$b[] = $x; 
			}
			
			foreach($b as $k3=>$v3){
				foreach($_args as $k2=>$v2){
					foreach($v2 as $kk2=>$vv2){
						if($v3==$vv2['name']){
							$f = $vv2['type'];
							$color = $vv2['color'];
							$width = $vv2['width'];
							$SMD = $vv2['chartSM'];
							if(is_numeric($vv2['value'])){
								if($_spArr==0){
									$_spArr = $vv2['value'];
								}else{
									$_spArr = $_spArr+$vv2['value'];
								}
							}
						}
					}
				}
				$this->_pic_n[] = $v3;
				$this->_pic_n[] = $_spArr;
				$this->_pic_n[] = $f;
				$this->_pic_n[] = $color;
				$this->_pic_n[] = $width;
				$this->_pic_n[] = $SMD;
				$_spArr = 0;
				$c[] = $this->_pic_n;
				$this->_pic_n = array();
			}
	
			foreach($c as $fk=>$fv){
				$d[] = $fv[0];
				$e[] = $fv[1];
				$g[] = $fv[2];
				$colors = $fv[3];
				$widths = $fv[4];
				$SMD = $fv[5];
			}
			$this->_tempArr[] = $d;
			$this->_tempArr[] = $e;
			$this->_tempArr[] = $g;
			$this->_tempArr[] = $colors;
			$this->_tempArr[] = $widths;
			$this->_tempArr[] = $SMD;
			#debug($this->_tempArr);
			return $this->_tempArr;
	 }
}
?>